package com.cl.cloud.auth.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.oauth2.common.exceptions.InsufficientScopeException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator;

/**
 * @description: 自定义oauth2异常 包括鉴权认证异常 和 资源认证异常
 * @author: liuzijian
 * @time: 2022-05-12 09:30
 */
@Slf4j
public class CustomWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {

    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
        log.warn("oauth2异常", e);
        //这里可以根据不同类型的oauth异常抛出不同的值
        //修改ResponseEntity里面的值可以给前端传更多的参数
        return super.translate(e);
    }
}
